﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DatNuocViet.Models;

namespace DatNuocViet.Controllers
{
    public class NewsController : Controller
    {
        //
        // GET: /News/
        public ActionResult Details(int id)
        {
            New news = Models.NewsDAO.GetNewsDetails(id);
            NewsType type = NewsDAO.GetNewsType((int)news.NewsType);

            ViewBag.newsTypeId = type.Id;
            ViewBag.NewsType = (Session["Language"].ToString() == "en") ? type.NewsTypeEn : type.NewsTypeVn;
            ViewBag.Title = (Session["Language"].ToString() == "en") ? news.TitleEn : news.TitleVn;

            /*tin lien quan*/
            List<SearchNewsResult> relateNews = new List<SearchNewsResult>();
            using (DatNuocVietDbDataContext db = new DatNuocVietDbDataContext())
            {
                relateNews = db.SearchNews(1, 7, string.Empty, type.Id, "[News].[CreateOn]", "desc", string.Empty).Where(n => n.NewsId != id).ToList();
            }
            ViewData["RelateNews"] = relateNews;
            /*end*/

            return View(news);
        }

        public ActionResult Index(int id)
        {
            ViewBag.nNews = Models.NewsDAO.getAmountOfNewsByType(id);
            ViewBag.id = id;

            NewsType type = NewsDAO.GetNewsType(id);

            ViewBag.Title = (Session["Language"].ToString() == "en") ? type.NewsTypeEn : type.NewsTypeVn;

            return View();
        }

        public ActionResult IndexPager(int? pageSize, int? pageNumber, int id)
        {
            int iPageNumber = (pageNumber ?? 1);
            int iPageSize = (pageSize ?? 10);

            List<New> listNews = Models.NewsDAO.GetNewsByType(iPageNumber, iPageSize, id);
            return View(listNews);
        }
    }
}
